﻿using System;
using System.Data;
using System.Linq;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        private void JLTRWB18D(DataSet db)
        {
            try
            {
                DataTable dtSoruce = db.Tables["WBFEHL"];
                DataTable dtOutput = new DataTable();
                dtOutput.Columns.Add("WBBEINDAT", typeof(System.String));
                dtOutput.Columns.Add("ARTICLE", typeof(System.String));
                dtOutput.Columns.Add("WBBSTKNR", typeof(System.String));
                dtOutput.Columns.Add("DEFECT", typeof(System.String));
                dtOutput.Columns.Add("WBFFSCHL", typeof(System.String));
                dtOutput.Columns.Add("DEFMTR", typeof(System.String));
                dtOutput.Columns.Add("STAFF", typeof(System.String));
                dtOutput.Columns.Add("WBBWBMLFDNR", typeof(System.String));
                dtOutput.Columns.Add("WBBWARSCH", typeof(System.String));
                dtOutput.Columns.Add("PCEMTR", typeof(System.String));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                foreach (DataRow row in dtOutput.Rows)
                {
                    row["STAFF"] = GetGB2312Value(row["STAFF"].ToString());
                    row["WBFFSCHL"] = GetGB2312Value(row["WBFFSCHL"].ToString());
                }
                exAgent.DataTableToExcel(dtOutput, 2, 1);

                int count = dtOutput.Rows.Count;
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 6, count + 1, 6);
                exAgent.BatchConvert2Number(2, 10, count + 1, 10);
                exAgent.SetCellValue(1, 1, "验布日期");

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void JLTRWB18DF(DataSet db)
        {
            try
            {
                DataTable dtrSoruce = db.Tables["WBFEHL"];
                int i = 2;
                string ROLL = "", ST = "";
                foreach (DataRow row in dtrSoruce.Rows)
                {
                    row["STAFF"] = GetGB2312Value(row["STAFF"].ToString());
                    row["WBFFSCHL"] = GetGB2312Value(row["WBFFSCHL"].ToString());
                }
                foreach (DataRow dw in dtrSoruce.Rows)
                {
                    string WBBSTKNR = dw["WBBSTKNR"].ToString().Trim();
                    string STAFF = dw["STAFF"].ToString().Trim();
                    if (ROLL == WBBSTKNR)
                    {
                        string DEFECT = dw["DEFECT"].ToString().Trim();
                        exAgent.SetCellValue(i, 4, DEFECT);
                        string WBFFSCHL = dw["WBFFSCHL"].ToString().Trim();
                        exAgent.SetCellValue(i, 5, WBFFSCHL);
                        string DEFMTR = dw["DEFMTR"].ToString().Trim();
                        exAgent.SetCellValue(i, 6, DEFMTR);
                        if (ST != STAFF)
                        {
                            exAgent.SetCellValue(i, 7, STAFF);
                            ST = STAFF;
                        }
                    }
                    else
                    { /*WBBEINDAT	ARTICLE	WBBSTKNR	DEFECT	WBFFSCHL	DEFMTR	STAFF	WBBWBMLFDNR	WBBWARSCH	PCEMTR*/
                        string WBBEINDAT = dw["WBBEINDAT"].ToString().Trim();
                        exAgent.SetCellValue(i, 1, WBBEINDAT);
                        string ARTICLE = dw["ARTICLE"].ToString().Trim();
                        exAgent.SetCellValue(i, 2, ARTICLE);
                        exAgent.SetCellValue(i, 3, WBBSTKNR);
                        string DEFECT = dw["DEFECT"].ToString().Trim();
                        exAgent.SetCellValue(i, 4, DEFECT);
                        string WBFFSCHL = dw["WBFFSCHL"].ToString().Trim();
                        exAgent.SetCellValue(i, 5, WBFFSCHL);
                        string DEFMTR = dw["DEFMTR"].ToString().Trim();
                        exAgent.SetCellValue(i, 6, DEFMTR);
                        exAgent.SetCellValue(i, 7, STAFF);
                        string WBBWBMLFDNR = dw["WBBWBMLFDNR"].ToString().Trim();
                        exAgent.SetCellValue(i, 8, WBBWBMLFDNR);
                        string WBBWARSCH = dw["WBBWARSCH"].ToString().Trim();
                        exAgent.SetCellValue(i, 9, WBBWARSCH);
                        string PCEMTR = dw["PCEMTR"].ToString().Trim();
                        exAgent.SetCellValue(i, 10, PCEMTR);
                        ROLL = WBBSTKNR;
                        ST = STAFF;

                    }

                    i = i + 1;
                }
                int count = dtrSoruce.Rows.Count;
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 6, count + 1, 6);
                exAgent.SetCellValue(1, 1, "验布日期");


            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }        
    }
}